﻿/*
* BaseSkill.h
*
* 技能基类
*
* create date: 2014.4.11
* create by: leo
*
*/

#ifndef _BASESKILL_H_
#define _BASESKILL_H_

#include "cocos2d.h"
#include "../Common.h"
#include "buffer/BaseBuffer.h"
#include "../armatures/HeroArmature.h"

class CBaseHero;

class CBaseSkill : public cocos2d::CCObject
{
public:
	typedef enum
	{
		EMPTY_SKILL = -1,
		WAITING, // 待机
		WALKING, // 行走
		BEATTACKED, // 被攻击
		DYING, // 死亡
		VICTORY, // 胜利
		COMMON_ATTACK, // 普通攻击
		AUTO_SKILL_1, // 自动技能1
	} Type;

	typedef enum
	{
		PHYSICAL, // 物理
		MAGIC // 魔法
	} SkillEffectType;

	typedef enum
	{
		ENEMY, // 敌人
		FRIEND, // 友军
		ALL // 所有
	} AimType;

public:
	typedef struct Param
	{
		cocos2d::CCString SkillName;
		CBaseSkill::Type Type;
		CBaseHero* BelongHero; // 属于英雄
		int AttackRange; // 攻击范围
		cocos2d::CCArray* ThrowObjs; // 飞行道具
		SkillEffectType EffectType; // 技能效果类型
		int EffectValue; // 技能效果值

		Param()
		: Type(EMPTY_SKILL),
		  BelongHero(NULL),
		  AttackRange(0),
		  ThrowObjs(NULL),
		  EffectType(PHYSICAL),
		  EffectValue(0)
		{
			ThrowObjs = cocos2d::CCArray::create();
			ThrowObjs->retain();
		}

		Param(const CBaseSkill::Param& param)
		: Type(param.Type),
		  SkillName(param.SkillName),
		  BelongHero(param.BelongHero),
		  ThrowObjs(NULL),
		  AttackRange(param.AttackRange),
		  EffectType(param.EffectType),
		  EffectValue(param.EffectValue)
		{
			ThrowObjs = cocos2d::CCArray::create();
			ThrowObjs->retain();
			cocos2d::CCObject* obj = NULL;
			CCARRAY_FOREACH(param.ThrowObjs, obj)
			{
				ThrowObjs->addObject(obj);
			}
		}

		Param(	CBaseSkill::Type type,
				cocos2d::CCString skillName,
				CBaseHero* belongHero,
				int attackRange,
				cocos2d::CCArray* throwObjs,
				SkillEffectType effectType,
				int effectValue
				)
		: Type(type),
		  SkillName(skillName),
		  BelongHero(belongHero),
		  ThrowObjs(NULL),
		  AttackRange(attackRange),
		  EffectType(effectType),
		  EffectValue(effectValue)
		{
			ThrowObjs = cocos2d::CCArray::create();
			ThrowObjs->retain();
			ThrowObjs->addObjectsFromArray(throwObjs);
		}

        ~Param()
        {
        	ThrowObjs->removeAllObjects();
        	ThrowObjs->release();
        }
	} Param;

public:
	/*
	 * 使用技能
	 */
	virtual void use() = 0;
	virtual void stop() = 0;
	/*
	 * 设置技能生效时回调
	 */
	void setOnSkillActCallback(cocos2d::CCObject* callbackObj, cocos2d::SEL_CallFuncO callback);
	/*
	 * 设置技能结束时回调
	 */
	void setOnSkillFinishCallback(cocos2d::CCObject* callbackObj,cocos2d::SEL_CallFuncO callback);

	cocos2d::CCString getSkillName();
	void setSkillName(const char* name);

	virtual void setArmature(CHeroArmature& armature, int index);
	virtual void setShadowArmature(CHeroArmature& armature, int index);

	CBaseSkill(const char* paramString);
	CBaseSkill(Param& param);
	virtual ~CBaseSkill();

	SkillEffectType getSkillEffectType();
	int getSkillEffectValue();

	bool isCrit();

protected:
	void doNothing(cocos2d::CCNode* obj);
    virtual void onFrameEvent(cocos2d::extension::CCBone *bone, const char *evt, int originFrameIndex, int currentFrameIndex);

    virtual void selectTargets();

protected:
	CHeroArmature* mArmature; // 动画集
	CHeroArmature* mShadowArmature; // 动画集
	int mAniIndex; // 动画编号

	cocos2d::CCObject* mOnActCallbackObj;
	cocos2d::SEL_CallFuncO mOnActCallback; // 技能生效时回调
	cocos2d::CCObject* mOnFinishCallbackObj;
	cocos2d::SEL_CallFuncO mOnFinishCallback; // 技能结束时回调

	cocos2d::CCArray mTriggerBuffers; // 触发效果

	int mEffectCount; // 选定目标数量
	cocos2d::CCString mSelectTargetAlg; // 选定目标算法
	cocos2d::CCString mTriggerAlg; // 技能触发条件
	cocos2d::CCPoint mChangeAimPos; // 改变目标位置
	AimType mAimType; // 作用于目标类型
	int mEffectRange; // 对目标周围生效范围
	cocos2d::CCPoint mEffectAlg; // 技能效果(对特殊状态目标不同效果)

	Param mParam;

};

#endif // _BASESKILL_H_
